
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="secure.UserRights"%>
<%@page import="util.Constant"%>
<%@page import="util.Hash"%>
 <% 
 		System.out.println(request.getParameter(Constant.PASSWORD));
 		String password_hash = Hash.plainStringToMD5(
 				request.getParameter(Constant.PASSWORD));		
        Long userid = UserRights.authenticateUser(request.getParameter(Constant.EMAIL),
        		request.getParameter(Constant.PASSWORD));
        if(userid!=null) {
            out.println("Login erfolgreich!"); 
            System.out.println("ADMIN EINGELOGGT: " + secure.UserRights.isUserAdmin(userid));
            System.out.println("User Role: " + UserRights.getUserRole(userid));
            session.setAttribute(Constant.USER_NAME, UserRights.getUserName(userid));
  	      	session.setAttribute(Constant.USERID, userid);
  	      	session.setAttribute(Constant.ROLE, UserRights.getUserRole(userid));
  	      	//session.setMaxInactiveInterval(10);
        	pageContext.forward("index.jsp");
        }
        else {
            out.println("Login fehlgeschlagen!"); 
        	pageContext.forward("index.jsp?content=error");
        } 
%>
